package springapp.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import springapp.entity.ReviewEntity;
import springapp.service.ReviewService;
import springapp.util.Utils;

import com.google.gson.Gson;

@Controller
public class ReviewController {

	@Autowired
	private ReviewService reviewService;

	@RequestMapping(value = "/getReviewsJson.htm", method = RequestMethod.GET)
	public @ResponseBody
	String getReviewsJson(@RequestParam("companyId") String companyId) {
		ReviewEntity[] reviews = reviewService.getReviewsForCompanyId(Utils
				.getInt(companyId));
		Gson gson = new Gson();
		String json = gson.toJson(reviews);
		return json;
	}
}
